/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ro.futurefeed.view;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import ro.futurefeed.model.FacebookQLUser;

/**
 *
 * @author georgian.micsa
 */
@FacesConverter("friendConverter")
public class FriendConverter implements Converter{
    public static final String SEPARATOR = ";";

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
        FacebookQLUser user = new FacebookQLUser();
        final String[] parts = string.split(SEPARATOR);
        user.setUid(parts[0]);
        user.setName(parts[1]);
        user.setPic_square(parts[2]);
        return user;
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object o) {
        FacebookQLUser friend = (FacebookQLUser) o;
        return friend.getUid() + SEPARATOR + friend.getName() + SEPARATOR + friend.getPic_square();
    }
    
}
